(function(){
	
	
var selectedUserCityId = "";	
	
	
function selectOneUserCityHandler(selectedCityId , latitude , longitude,cityName){
	
	var location = $gmap.createLocation(latitude , longitude);
    var imageUrl = "/public/images/defaultMarker.png";
    $gmap.removeLastAddedMarker();
    $gmap.addMarkerToMap(location,imageUrl,cityName);
}	
	
	
function selectOneUserPlaceHandler(selectedPlaceId , latitude ,longitude , placeName){
	alert(selectedPlaceId);
}	
	
function fillUserPlaceTable(userPlaceResult){
   $('.onePlace').remove();
   
   var seePlace = new Array();
   var eatPlace = new Array();
   var stayPlace = new Array();
   if(userPlaceResult.success == true){
   	  if(userPlaceResult.size > 0){
   	  	 for(i = 0; i < userPlaceResult.size; i++){
   	  	 	var userPlace = userPlaceResult
   	  	 }
   	  	
   	  }
   }
   	
}	

function createLiElemetForOnePlaces(){
	var liElement = $("<li>").attr({'id':cityId,
	                                'class':'oneCity',
	                                 'lat':lat,
	                                 'lgt':lgt});
	var pElement = $("<p>").html(cityName);
	liElement.append(spanElement);
	return liElement; 
}

 	
function userCitiesClickBinding(){
	$(".oneCity").each(function(index) {
	  var thisCity = $(this);
	  thisCity.click(function(){
	  var cityId = thisCity.attr("id");
	  var latitude = thisCity.attr("lat");
	  var longitude = thisCity.attr("lgt");
	  var cityName = thisCity.find("p").eq(0).html();
	  selectOneUserCityHandler(cityId,latitude,longitude,cityName);
	  });
	});
	
}	
	

function userPlaceClickBinding(){
	$(".onePlace").each(function(index){
		var thisPlace = $(this);
		thisPlace.click(function(){
			var placeId = thisPlace.attr("id");
			var latitude = thisPlace.attr("lat");
			var longitute = thisPlace.attr("lgt");
			selectOneUserPlaceHandler(placeId, latitude , longitute)
		});
	});
}


function initialize(){
	$gmap.setLatitude(-34.397).setLongitude(150.644).mapInit();
	userCitiesClickBinding();
	userPlaceClickBinding();
    
}	


initialize();	
})()
